<template>
  <div>
    <van-button size="mini" type="default" @click="isShow = true"
      >回复</van-button
    >
    <van-popup v-model="isShow" position="bottom" :style="{ height: '35%' }">
      <van-field
        v-model="message"
        rows="3"
        autosize
        type="textarea"
        maxlength="30"
        placeholder="请输入回复内容"
        show-word-limit
      />
      <van-button type="primary" @click="replayComment">回复</van-button>
    </van-popup>
  </div>
</template>

<script>
import { addComments } from '@/api/comment'
export default {
  name: 'WriteReplay',
  inject: ['aid', 'cmt', 'replayList'],

  data () {
    return {
      message: '',
      isShow: false
    }
  },

  mounted () {},

  methods: {
    // 回复评论
    async replayComment () {
      try {
        const res = await addComments(this.cmt.com_id, this.message, this.aid)
        const newObj = res.data.data.new_obj
        console.log('回复', newObj, res)
        this.replayList.unshift(newObj)
        this.isShow = false
        this.message = ''
      } catch (error) {
        console.log('错误', error.target)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
